同じBounded Context内でのConsistency
同期的に保つか、非同期的に保つかは場合による
1つのtransactionで複数のAggregateを同時に更新すべきでない
そこで、今更新したい2つの間の操作を新しいAggregate(Entity)で表現できないか?を考える
例えば、2つのアカウントでお金を送金し合うものを考える
Account (=口座)が、既にAggregateで表現されているとする
この時、こういうAPIのやり取りをするのではなく、
code:aa
Strat transaction
Add X amount to accountA
Remove X amount from accountB
Commit transaction
こういうEntityを新規に作る
code:hs
data MoneyTransfer = MoneyTransfer
{ Id: MoneyTransferId
, ToAccount: AccountId
, FromAccount: AccountId
, Amount: Money
}
MoneyTransfer集約目線だと、Accoutは異なる集約なのでIDで参照している
参考